#include "front/text_normalize.h"

using namespace std;
using namespace ppspeech;

const wregex mcWregexCentury(L"(\\d+世纪)(\\d+年代)?");

void TextNormalizer::TnReChineseCentury(wstring* fInWsentence, const LanguageEnum fcInLanguage)
{
	wsmatch tWsmatch;

	while (regex_search(*fInWsentence, tWsmatch, mcWregexCentury)) {
		string tStrCentury = wstring2utf8string(tWsmatch[0]);		//匹配到世纪的字符串

		const size_t tcPosCentury = tStrCentury.find("世纪");
		const size_t tcPosYears = tStrCentury.find("年代");

		string tStrReplace = "";

		if(tcPosCentury != string::npos) {
			tStrReplace += ReplaceMethod(vector<string>{tStrCentury.substr(0, tcPosCentury)}, (fcInLanguage==LANG_EN)?RME_en_negative_decimal:RME_zh_negative_decimal);
			tStrReplace += "世纪";
		}
		if(tcPosYears != string::npos) {
			tStrReplace += ReplaceMethod(vector<string>{tStrCentury.substr(tcPosCentury+6, tcPosYears-tcPosCentury-6)}, (fcInLanguage==LANG_EN)?RME_en_negative_decimal:RME_zh_negative_decimal);
			tStrReplace += "年代";
		}

		WstrReplacePosition(fInWsentence, tWsmatch.position(0), tWsmatch.length(0), utf8string2wstring(tStrReplace));
	}
}
